package com.huawei.hianalytics.ab.bc.ab;

import android.text.TextUtils;
import com.huawei.hianalytics.ab.bc.ef.ab;
import java.security.SecureRandom;
import java.util.Locale;

public abstract class de {
    private static final char[] ab = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    private static byte ab(char c) {
        return (byte) "0123456789ABCDEF".indexOf(c);
    }

    static String ab(int i) {
        byte[] bArr = new byte[i];
        new SecureRandom().nextBytes(bArr);
        return ab(bArr);
    }

    static String ab(byte[] bArr) {
        if (bArr == null || bArr.length == 0) {
            ab.cd("HexUtil", "byteArray is empty");
            return "";
        }
        StringBuilder stringBuilder = new StringBuilder(bArr.length * 2);
        for (byte b : bArr) {
            stringBuilder.append(ab[(b & 240) >> 4]).append(ab[b & 15]);
        }
        return stringBuilder.toString();
    }

    static byte[] ab() {
        byte[] bArr = new byte[16];
        new SecureRandom().nextBytes(bArr);
        return bArr;
    }

    static byte[] ab(String str) {
        int i = 0;
        if (TextUtils.isEmpty(str)) {
            return new byte[0];
        }
        String toUpperCase = str.toUpperCase(Locale.ENGLISH);
        int length = toUpperCase.length() / 2;
        char[] toCharArray = toUpperCase.toCharArray();
        byte[] bArr = new byte[length];
        while (i < length) {
            int i2 = i * 2;
            bArr[i] = (byte) (ab(toCharArray[i2 + 1]) | (ab(toCharArray[i2]) << 4));
            i++;
        }
        return bArr;
    }
}
